package com.da.javatest.leetCode;

/**
 * @author chenlida
 * @date 2019/2/16 11:20
 * @description
 */
public class Code477 {
    public static void main(String[] args) {
        System.out.println(new Code477().totalHammingDistance(new int[] {2, 4, 14}));
    }

    public int totalHammingDistance(int[] nums) {
        int sum = 0;
        for (int i = 0; i < nums.length; i++) {
            for (int j = i + 1; j < nums.length; j++) {
                sum += HammingDistance(nums[i], nums[j]);
            }
        }
        return sum;
    }

    private int HammingDistance(int num1, int num2) {
        String s = Integer.toBinaryString(num1 ^ num2);
        return s.replace("0", "").length();
    }
}
